package com.cls.business.service.impl;

import com.cls.business.entity.Indicator;
import com.cls.common.entity.QueryRequest;
import com.cls.business.entity.IndicatorDetail;
import com.cls.business.mapper.IndicatorDetailMapper;
import com.cls.business.service.IIndicatorDetailService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

/**
 * 评审指标详情表 Service实现
 *
 * @author slx
 * @date 2020-11-13 15:15:11
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class IndicatorDetailServiceImpl extends ServiceImpl<IndicatorDetailMapper, IndicatorDetail> implements IIndicatorDetailService {

    @Override
    public PageInfo<IndicatorDetail> findIndicatorDetails(QueryRequest request, IndicatorDetail indicatorDetail) {
        LambdaQueryWrapper<IndicatorDetail> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        if(indicatorDetail.getIndicatorId()!=null) {
            queryWrapper.eq(IndicatorDetail::getIndicatorId, indicatorDetail.getIndicatorId());
        }
        queryWrapper.orderByAsc(IndicatorDetail::getIndicatorType);
        List<IndicatorDetail> list= this.list(queryWrapper);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<IndicatorDetail> findIndicatorDetails(IndicatorDetail indicatorDetail) {
	    LambdaQueryWrapper<IndicatorDetail> queryWrapper = new LambdaQueryWrapper<>();
	    if(indicatorDetail.getIndicatorId()!=null){
        queryWrapper.eq(IndicatorDetail::getIndicatorId, indicatorDetail.getIndicatorId());
	    }
        queryWrapper.orderByAsc(IndicatorDetail::getIndicatorType);
        queryWrapper.orderByDesc(IndicatorDetail::getCreateTime);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }
    @Override
    public List<IndicatorDetail> findListsOrderByLev(IndicatorDetail indicatorDetail) {
        LambdaQueryWrapper<IndicatorDetail> queryWrapper = new LambdaQueryWrapper<>();
        if(indicatorDetail.getIndicatorId()!=null) {
            queryWrapper.eq(IndicatorDetail::getIndicatorId, indicatorDetail.getIndicatorId());
        }
        queryWrapper.orderByAsc(IndicatorDetail::getIndicatorType);
        // TODO 设置查询条件
        return this.baseMapper.selectList(queryWrapper);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createIndicatorDetail(IndicatorDetail indicatorDetail) {
        this.save(indicatorDetail);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateIndicatorDetail(IndicatorDetail indicatorDetail) {
        this.saveOrUpdate(indicatorDetail);
    }


    /**
    * 删除
    * @param ids
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteIndicatorDetails(String[] ids) {
        List< String > list = Arrays.asList(ids);
        this.removeByIds(list);
     }

}
